using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL {

/// <summary>
/// The RaceCodeTableManager class is responsible for managing BO.RaceCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class RaceCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all RaceCodeTable objects in the database.
/// </summary>
/// <returns>A list with all RaceCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static RaceCodeTableList GetList(){
return RaceCodeTableDB.GetList();
}

/// <summary>
/// Gets a single RaceCodeTable from the database without its data.
/// </summary>
/// <param name="raceCode">The RaceCode of the RaceCodeTable in the database.</param>
/// <returns>A RaceCodeTable object when the RaceCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static RaceCodeTable GetItem(short raceCode,int SchoolKey){
return GetItem(raceCode,SchoolKey, false);
}

/// <summary>
/// Gets a single RaceCodeTable from the database.
/// </summary>
/// <param name="raceCode">The RaceCode of the RaceCodeTable in the database.</param>
/// <param name="getRaceCodeTableRecords">Determines whether to load all associated RaceCodeTable records as well.</param>
/// <returns>
/// A RaceCodeTable object when the RaceCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static RaceCodeTable GetItem(short raceCode,int SchoolKey, bool getRaceCodeTableRecords){
RaceCodeTable myRaceCodeTable = RaceCodeTableDB.GetItem(raceCode);
if (myRaceCodeTable != null && getRaceCodeTableRecords){
myRaceCodeTable.familyMemberProfileTables = FamilyMemberProfileTableDB.GetListByRaceCode(raceCode);
}
if (myRaceCodeTable != null && getRaceCodeTableRecords){
myRaceCodeTable.guardianProfileTables = GuardianProfileTableDB.GetListByRaceCode(raceCode);
}
if (myRaceCodeTable != null && getRaceCodeTableRecords){
myRaceCodeTable.studentProfileTables = StudentProfileTableDB.GetListByRaceCode(raceCode);
}
if (myRaceCodeTable != null && getRaceCodeTableRecords){
myRaceCodeTable.teacherProfileTables = TeacherProfileTableDB.GetListByRaceCode(raceCode,SchoolKey);
}
if (myRaceCodeTable != null && getRaceCodeTableRecords){
myRaceCodeTable.userProfileTables = UserProfileTableDB.GetListByRaceCode(raceCode);
}
return myRaceCodeTable;
}

/// <summary>
/// Saves a RaceCodeTable in the database.
/// </summary>
/// <param name="myRaceCodeTable">The RaceCodeTable instance to save.</param>
/// <returns>The new RaceCode if the RaceCodeTable is new in the database or the existing RaceCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static short Save(RaceCodeTable myRaceCodeTable){
using (TransactionScope myTransactionScope = new TransactionScope()){
short raceCodeTableRaceCode = RaceCodeTableDB.Save(myRaceCodeTable);
foreach (FamilyMemberProfileTable myFamilyMemberProfileTable in myRaceCodeTable.familyMemberProfileTables){
myFamilyMemberProfileTable.RaceCode = raceCodeTableRaceCode;
FamilyMemberProfileTableDB.Save(myFamilyMemberProfileTable);
}
foreach (GuardianProfileTable myGuardianProfileTable in myRaceCodeTable.guardianProfileTables){
myGuardianProfileTable.RaceCode = raceCodeTableRaceCode;
GuardianProfileTableDB.Save(myGuardianProfileTable);
}
foreach (StudentProfileTable myStudentProfileTable in myRaceCodeTable.studentProfileTables){
myStudentProfileTable.RaceCode = raceCodeTableRaceCode;
StudentProfileTableDB.Save(myStudentProfileTable);
}
foreach (TeacherProfileTable myTeacherProfileTable in myRaceCodeTable.teacherProfileTables){
myTeacherProfileTable.RaceCode = raceCodeTableRaceCode;
TeacherProfileTableDB.Save(myTeacherProfileTable);
}
foreach (UserProfileTable myUserProfileTable in myRaceCodeTable.userProfileTables){
myUserProfileTable.RaceCode = raceCodeTableRaceCode;
UserProfileTableDB.Save(myUserProfileTable);
}

//  Assign the RaceCodeTable its new (or existing RaceCode).
myRaceCodeTable.RaceCode = raceCodeTableRaceCode;

myTransactionScope.Complete();

return raceCodeTableRaceCode;
}
}

/// <summary>
/// Deletes a RaceCodeTable from the database.
/// </summary>
/// <param name="myRaceCodeTable">The RaceCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(RaceCodeTable myRaceCodeTable){
return RaceCodeTableDB.Delete(myRaceCodeTable.RaceCode);
}

#endregion

}

}
